
import star from '../../assets/star.png'
import Phaser from 'phaser'
import dude from '../../assets/dude.png'

export default class GroupScene extends Phaser.Scene {

    constructor() {
        super('groupScene')
    }

    // Initialization code here
    init(data) {
        console.log('--init--')
    }

    // Preload assets here
    preload() {
        console.log('--preload--')
        this.load.image('star', star);
        this.load.spritesheet('dude',
            dude,
            { frameWidth: 32, frameHeight: 48 }
        );
    }

    // 添加元素的方法
    // this.add.image(x, y, textureKey)
    // this.add.graphics() 动态绘制矩形、圆形、线条
    // this.add.sprite(x, y, textureKey) 添加可动画、交互的对象
    // this.add.text(x, y, content, style) 添加文字说明或数值显示
    // Create game objects and set up the scene here 
    create() {
        console.log('--create--')
        let starImg = this.add.image(200, 200, 'star')
        // 创建组
        // const enemyGroup = this.add.group({
        //     classType: Phaser.GameObjects.Sprite,
        //     defaultKey: 'star',
        //     maxSize: 10
        // });

        // const enemyGenerator = this.time.addEvent({
        //     delay: 2000,
        //     callback: () => enemyGroup.create(Phaser.Math.Between(0,600), 0),
        //     callbackScope: this,
        //     loop: true  // 重复9次，加上第一次，一共10个敌人
        // });



        //创建物理组
       const physicsGroup =  this.physics.add.group(
         {  
            gravityY: 300,   // 重力大小，正值表示向下
            bounceX: 0.5,    // 弹性系数
            bounceY: 0.5,
            collideWorldBounds: true  // 允许与世界边界碰撞
        });


        const physicsGroupItem = this.time.addEvent({
            delay: 2000,
            callback: () => physicsGroup.create(Phaser.Math.Between(0,600), 0,'star'),
            callbackScope: this,
            loop: true  // 重复9次，加上第一次，一共10个敌人
        });
    }




    // Update game logic each frame here
    update(time, delta) {
    }
}

class SelfSpriter extends Phaser.GameObjects.Sprite {



}

class SelfRect extends Phaser.GameObjects.Rectangle {



}